/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package AWT;

import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 *
 * @author gurrola
 */
public class VentanaTexto {

     TextField tf = new TextField();
     TextArea ta = new TextArea();
     Button b = new Button("Agregar");
     Button b2 = new Button ("Reset");
     MenuBar mb = new MenuBar();
     Menu m = new Menu("menu");
     MenuItem miA = new MenuItem("nuevo");
     MenuItem miB = new MenuItem("salir");

     
    public VentanaTexto(){
             
     Frame f = new Frame("Gurrola");

    // f.setLayout(new GridLayout(2, 1));
     f.setBounds(300, 200, 600, 500);
     f.setVisible(true);
 

     Panel p = new Panel();
     p.add(tf);
     p.add(b);
     p.add(b2);
     f.add(p);

     f.setMenuBar(mb);
     mb.add(m);
     m.add(miA);
     m.add(miB);


     Panel p1 = new Panel();
     p1.add(ta);
     f.add(p1,"North");


    f.addWindowListener(new WindowAdapter() {
       public void windowClosing(WindowEvent evt){
            System.exit(0);
    }

    });

    class ManejarBoton implements ActionListener {
        public void actionPerformed(ActionEvent e) {
           ta.append(tf.getText() + '\n');
        }

    }

    class Teclas extends KeyAdapter{
        public void keyPressed(KeyEvent evt){
        if(evt.getKeyCode()==10)
            ta.append('\n' + tf.getText());
        }
    }

    class CambioColor extends MouseAdapter {
        public void mouseEntered(MouseEvent evt){
            b.setBackground(Color.red);
        }
        public void mouseExited(MouseEvent evt){
            b.setBackground(Color.yellow);
        }

    }

    class CambioColor2 extends MouseAdapter{
        public void mouseEntered(MouseEvent ev){
            b2.setBackground(Color.CYAN);
        }
        public void mouseExited(MouseEvent ev){
            b2.setBackground(Color.GREEN);
        }
    }

    miA.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ta.setText("");
            }
        });

    miB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
               System.exit(0);
            }
        });
    
    ManejarBoton mv = new ManejarBoton();
    b.addActionListener(mv);   

    Teclas t = new Teclas();
    tf.addKeyListener(t);

    CambioColor camb = new CambioColor();
    b.addMouseListener(camb);

    CambioColor2 cam2 = new CambioColor2();
    b2.addMouseListener(cam2);

    }

     public static void main (String [] args ){
         VentanaTexto v = new VentanaTexto();
         
  } 
   
}
